﻿<?php require_once(dirname(__FILE__)."/../config/config.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>礼品浏览页面</title>
</head>
<body>
<style type="text/css">
<!--
a:link {
 text-decoration: none;
}
a:visited {
 text-decoration: none;
}
a:hover {
 text-decoration: none;
}
a:active {
 text-decoration: none;
}
-->
</style>
<?php  
if($_SESSION['admin_name']=="")
{

	echo "<script>location.href='admin_login.php';</script>";
}
?>
<center>
<?php include("giftmenu.php"); ?>
 <h3>分页浏览礼品信息</h3>
<table width="843" border="1" align="center">
 <tr>
   
  
	<th width="95">礼品名字</th>  
	<th width="95">礼品兑换积分数</th>
	<th width="142">礼品小图路径</th>
	<th width="142">礼品大图路径</th>
	<th width="200">礼品描述</th>
	<th width="155">操作</th>
	
	
</tr>

 <?php 
 //========================
 // 1 定义分页变量
 	$page = isset($_GET["page"])?$_GET["page"]:1;					//当前页号
	$pageSize = 20;				//页面大小	
	$maxRows;					// 最大数据条
	$maxPages;					// 最大页数
 	
 
 // 2获取最大数据条数
 	$sql = "select count(*) from zy_gift";
	$res = mysql_query($sql);
	$maxRows = mysql_result($res,0,0);//定位获取总条数
 
 
 // 3计算出共计最大页数
 	$maxPages=ceil($maxRows/$pageSize);
	$init = 1;
	$max = $maxPages;
	$pagelen = 10;
	// $pagelen = ($pagelen%2)?$pagelen:$pagelen+1;
	$pageoffset = 4;
	if($maxPages>$pagelen){
		if($page<=$pageoffset)
		{
			// echo "~~~~~~~~";
			$init=1;
			$max = $pagelen;
		}else{
			if($page+$pageoffset>=$maxPages+1){
				$init = $maxPages-$pagelen+1;
				// echo "!!!!!!!!!!";
			}else{
				// echo "????????????";
				$init = $page-$pageoffset;
				$max=$page+$pageoffset+1;
			}	
		}
	
	}
	
	
 
 // 4 效验当前页数
 	if($page>$maxPages){
		$page=$maxPages;
	}
	if($page<1){
		$page=1;
	}
 
 
 
 //5 拼装分页sql语句片段
	$limit = " limit ".(($page-1)*$pageSize).",{$pageSize}"; 
 
 
 
 
 //==========================
 $sql = "SELECT * FROM zy_gift  order by gift_id desc {$limit}";
 // echo $sql;
 $result = mysql_query($sql);
 
 while($zy_gift = mysql_fetch_array($result)){
 ?>

  <tr>
   
   
	<td><?php echo $zy_gift['gift_name']?></td>
	<td><?php echo $zy_gift['integral']?></td>
	<td><img src="<?php echo SITE_ROOT;?><?php echo $zy_gift['image']?>" width="100" height="80"  /></td>
	<td><img src="<?php echo SITE_ROOT;?><?php echo $zy_gift['image2']?>" width="100" height="80" /></td>
	<td><?php echo $zy_gift['description']?></td>
	<td align="center"><a href="gift_action.php?action=del&gift_id=<?php echo $zy_gift['gift_id'];?>&page=<?php echo $page ?>">删除</a>&nbsp;&nbsp;	    <a href="gift_edit.php?gift_id=<?php echo $zy_gift['gift_id'];?>&page=<?php echo $page?>">修改</a></td>
  </tr>

  <?php } ?>
 
</table>
<?php
	//输出分页信息显示上一页和下一页
	echo "<br/><br/>";
	if($page!=1){
  echo "<a href='gift.php?page=1'>首页</a> ";
  echo "<a href='gift.php?page=".($page-1)."'>上一页</a> ";
 }
 for($i=$init;$i<=$max;$i++){?>
  <a href="gift.php?page=<?php echo $i;?>;" <?php echo $i==$page ? "style='text-decoration: underline;font-weight: bold;'":''?> ><?php echo $i;?></a>
 <?php 
 }
 if($page!=$maxPages){
  echo "<a href='gift.php?page=".($page+1)."'>下一页</a> ";
   echo "<a href='gift.php?page={$maxPages}'>末页</a> ";
  
 }
?>
</center>
<h3 align="center"><a href="admin_management.php">返回</a></h3>
</body>
</html>
